﻿using OxyPlot;
using OxyPlot.Axes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OxyPlotChartingDemo
{
    public class MainViewModel : INotifyPropertyChanged
    {
        public MainViewModel()
        {
            //this._points = new List<DataPoint>
            //                  {
            //                      new DataPoint(0, 4),
            //                      new DataPoint(10, 13),
            //                      new DataPoint(20, 15),
            //                      new DataPoint(30, 16),
            //                      new DataPoint(40, 12),
            //                      new DataPoint(50, 12),
            //                  };

            //this._morePoints = new List<DataPoint>
            //                  {
            //                      new DataPoint(0, 4),
            //                      new DataPoint(15, 18),
            //                      new DataPoint(25, 100),
            //                      new DataPoint(35, 21),
            //                      new DataPoint(45, 17),
            //                      new DataPoint(55, 17)
            //                  };

            this._failurePoints = new List<DataPoint>
                              {
                                  new DataPoint(DateTimeAxis.ToDouble(new DateTime(2015,1,1)),TimeSpanAxis.ToDouble(new TimeSpan(0,1,10,15,0))),
                                  new DataPoint(DateTimeAxis.ToDouble(new DateTime(2015,1,2)),TimeSpanAxis.ToDouble(new TimeSpan(0,2,15,15,0))),
                                  new DataPoint(DateTimeAxis.ToDouble(new DateTime(2015,1,3)),TimeSpanAxis.ToDouble(new TimeSpan(0,23,22,56,0))),
                                  new DataPoint(DateTimeAxis.ToDouble(new DateTime(2015,1,4)),TimeSpanAxis.ToDouble(new TimeSpan(7,23,56,25,0))),
                                  new DataPoint(DateTimeAxis.ToDouble(new DateTime(2015,1,5)),TimeSpanAxis.ToDouble(new TimeSpan(0,0,20,15,0))),
                                  new DataPoint(DateTimeAxis.ToDouble(new DateTime(2015,1,6)),TimeSpanAxis.ToDouble(new TimeSpan(5,0,0,0,0))),
                                  new DataPoint(DateTimeAxis.ToDouble(new DateTime(2015,1,7)),TimeSpanAxis.ToDouble(new TimeSpan(2,2,15,0,0))),
                              };

            this._successPoints = new List<DataPoint>
                              {
                                  new DataPoint(DateTimeAxis.ToDouble(new DateTime(2015,1,1)),TimeSpanAxis.ToDouble(new TimeSpan(0,0,30,15,0))),
                                  new DataPoint(DateTimeAxis.ToDouble(new DateTime(2015,1,2)),TimeSpanAxis.ToDouble(new TimeSpan(0,0,45,0,0))),
                                  new DataPoint(DateTimeAxis.ToDouble(new DateTime(2015,1,3)),TimeSpanAxis.ToDouble(new TimeSpan(0,5,22,56,0))),
                                  new DataPoint(DateTimeAxis.ToDouble(new DateTime(2015,1,4)),TimeSpanAxis.ToDouble(new TimeSpan(3,23,56,25,0))),
                                  new DataPoint(DateTimeAxis.ToDouble(new DateTime(2015,1,5)),TimeSpanAxis.ToDouble(new TimeSpan(0,12,10,15,0))),
                                  new DataPoint(DateTimeAxis.ToDouble(new DateTime(2015,1,6)),TimeSpanAxis.ToDouble(new TimeSpan(2,0,0,0,0))),
                                  new DataPoint(DateTimeAxis.ToDouble(new DateTime(2015,1,7)),TimeSpanAxis.ToDouble(new TimeSpan(1,2,15,0,0))),
                              };

            this.MinimumInterval = DateTimeAxis.ToDouble(new DateTime(2014, 12, 31));
            this.MaxInterval = DateTimeAxis.ToDouble(new DateTime(2015, 1, 8));
        }

        public string Title { get; private set; }

        private IList<DataPoint> _failurePoints;

        public IList<DataPoint> FailurePoints
        {
            get 
            { 
                return _failurePoints; 
            }
            set 
            {
                _failurePoints = value;
                RaisePropertyChanged("FailurePoints");
            }
        }

        private IList<DataPoint> _successPoints;

        public IList<DataPoint> SuccessPoints
        {
            get 
            { 
                return _successPoints; 
            }
            set 
            { 
                _successPoints = value;
                RaisePropertyChanged("SuccessPoints");
            }
        }

        private double _minimumInterval;

        public double MinimumInterval
        {
            get 
            { 
                return _minimumInterval; 
            }
            set 
            { 
                _minimumInterval = value; 
            }
        }

        private double _maxInterval;

        public double MaxInterval
        {
            get 
            {
                return _maxInterval; 
            }
            set 
            {
                _maxInterval = value; 
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void RaisePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;

            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
